package office.action.hr;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import office.BusiUtil;
import office.action.hr.form.MatterSpecifyConditionForm;
import office.action.hr.form.MatterSpecifyForm;
import office.action.hr.wrapper.MatterSpecifyWrapper;
import office.service.hr.IMatterSpecifyService;
import platform.common.action.BaseAction;
import platform.common.bo.Page;
import current.security.user.manager.service.UserManagerService;

/**
 * 
 * 供应商
 * 
 * @author ZhangYQ
 * 
 */
public class MatterSpecifyAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private IMatterSpecifyService matterSpecifyService;
	private Page page; // 分页信息
	private List<MatterSpecifyWrapper> wrapperList;
	private MatterSpecifyForm form;
	private MatterSpecifyConditionForm condition;
	private String id;
	@SuppressWarnings("unchecked")
	private List userList;
	@Resource
	private UserManagerService userManagerService;
	/**
	 * 获取所有的其它事项指定交班人以及根据条件进行查询
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findAllMatterSpecify() throws Exception {
		String resultString="listMatterSpecifyByPage";
		if(condition==null){
			resultString="findAllMatterSpecify";
			condition=new MatterSpecifyConditionForm();
		}
		condition.setHandleUser(getUserId());
		page = matterSpecifyService.getPageInfo(condition);
		wrapperList = matterSpecifyService.findAllMatterSpecify(condition,page);
		return resultString;
	}

	/**
	 * 初始化编辑其它事项指定交班人页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEditMatterSpecify() throws Exception {
		if(null!=id&&!"".equals(id)){
			form = matterSpecifyService.getById(id);
		}else{
			form=new MatterSpecifyForm();
			form.setHandleState("0");
		}
		if(BusiUtil.validateRole(getUserRoleName())){
			userList = userManagerService.getUsersByAllDepartment(getUserDepartmentId());
		}
		return "gotoEditMatterSpecify";
	}

	/**
	 * 编辑其它事项指定交班人
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editMatterSpecify() throws Exception {
		try {
			//创建人
			form.setCreateMan((String)getUserMap().get("userId"));
			//创建时间
			form.setCreateDate(new Date());
			matterSpecifyService.editMatterSpecify(form);
			if (null == form.getId()
					|| ("").equals(form.getId())) {
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			} else {
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}

		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	/**
	 * 
	 * <br/>
	 * 方法描述:分页条件查询产品结构
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listMatterSpecifyByPage() throws Exception {
		try {
			if(condition.getHandleUser()==null){
				condition.setHandleUser((String)getUserMap().get("userId"));
			}
			wrapperList = matterSpecifyService.findAllMatterSpecify(condition, page);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "listMatterSpecifyByPage";
	}

	/**
	 * 初始化产品结构列表操作菜单
	 * 
	 * @return
	 * @throws Exception
	 */

	public String gotoMatterSpecifyMenu() throws Exception {
		form=matterSpecifyService.getById(id);
		return "gotoMatterSpecifyMenu";
	}

	/**
	 * 跳转到其它事项指定交班人删除确认页面
	 */
	public String gotoDeleteMatterSpecify(){
		return "gotoDeleteMatterSpecify";
	}
	
	/**
	 * 跳转到处理事项确认页面
	 */
	public String gotoDeleteHandleMatterSpecify(){
		return "gotoDeleteHandleMatterSpecify";
	}
	
	/**
	 * 对处理事项进行处理完成操作
	 * @return
	 * @throws Exception
	 */
	public String handelMatterSpecify() throws Exception {
		try {
			matterSpecifyService.handleMatter(id);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 删除其它事项指定交班人
	 * @return
	 * @throws Exception
	 */
	public String delMatterSpecify() throws Exception {
		try {
			matterSpecifyService.delMatterSpecifyById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return RESULT_AJAXJSON;
	}

	public IMatterSpecifyService getMatterSpecifyService() {
		return matterSpecifyService;
	}

	public void setMatterSpecifyService(IMatterSpecifyService matterSpecifyService) {
		this.matterSpecifyService = matterSpecifyService;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<MatterSpecifyWrapper> getWrapperList() {
		return wrapperList;
	}

	public void setWrapperList(List<MatterSpecifyWrapper> wrapperList) {
		this.wrapperList = wrapperList;
	}

	public MatterSpecifyForm getForm() {
		return form;
	}

	public void setForm(MatterSpecifyForm form) {
		this.form = form;
	}

	public MatterSpecifyConditionForm getCondition() {
		return condition;
	}

	public void setCondition(MatterSpecifyConditionForm condition) {
		this.condition = condition;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@SuppressWarnings("unchecked")
	public List getUserList() {
		return userList;
	}

	@SuppressWarnings("unchecked")
	public void setUserList(List userList) {
		this.userList = userList;
	}

	public UserManagerService getUserManagerService() {
		return userManagerService;
	}

	public void setUserManagerService(UserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}

}
